#include "MPC5604B_M07N.h"
#include "Driver_MPC5604B.h"
#include "delays.h"
void LED(void)
{
	SIU.PCR[68].R = 0x0200;				/* Program the drive enable pin of LED1 (PE4) as output*/
	SIU.PCR[69].R = 0x0200;				/* Program the drive enable pin of LED2 (PE5) as output*/
	SIU.PCR[70].R = 0x0200;				/* Program the drive enable pin of LED3 (PE6) as output*/
	SIU.PCR[71].R = 0x0200;				/* Program the drive enable pin of LED4 (PE7) as output*/
	
	Delayled();
	SIU.PGPDO[2].R |= 0x0f000000;		/* Disable LEDs*/
	SIU.GPDO[68].B.PDO = HIGH;		/* Enable LED1*/
	
	Delayled();
	SIU.GPDO[68].B.PDO = HIGH;		/* Disable LED1*/
	SIU.GPDO[69].B.PDO = LOW;		/* Enable LED2*/
	
	Delayled();
	SIU.GPDO[69].B.PDO = HIGH;		/* Disable LED2*/
	SIU.GPDO[70].B.PDO = LOW;		/* Enable LED3*/
	
	Delayled();
	SIU.GPDO[70].B.PDO = HIGH;		/* Disable LED3*/
	SIU.GPDO[71].B.PDO = LOW;		/* Enable LED4*/
	
	Delayled();
	SIU.GPDO[71].B.PDO = HIGH;		/* Disable LED4*/
}

void SWITCH(void)
{
	SIU.PCR[64].R = 0x0100;				/* Program the drive enable pin of S1 (PE0) as input*/
	SIU.PCR[65].R = 0x0100;				/* Program the drive enable pin of S2 (PE1) as input*/
	SIU.PCR[66].R = 0x0100;				/* Program the drive enable pin of S3 (PE2) as input*/
	SIU.PCR[67].R = 0x0100;				/* Program the drive enable pin of S4 (PE3) as input*/
	/*
	while((SIU.PGPDI[2].R & 0x80000000) == 0x80000000); 

	while((SIU.PGPDI[2].R & 0x40000000) == 0x40000000); 

	while((SIU.PGPDI[2].R & 0x20000000) == 0x20000000); 

	while((SIU.PGPDI[2].R & 0x10000000) == 0x10000000); 
	*/
}

void SERVO(double valor)
{
	EMIOS_0.CH[4].CBDR.R = valor;	
}

